/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Consultar.java
 *
 * Created on 02/11/2011, 12:00:14
 */
package Interfaces;

import classes.AreaTematica;
import classes.EventoPrincipal;
import classes.Palestrante;
import classes.Recurso;
import conexaoBD.mySQLconnection;
import conexaoBD.mySQLcrud;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListModel;

/**
 *
 * @author Kazuo
 */
public class TelaCadastroMiniCurso extends javax.swing.JFrame {

    private mySQLcrud connectionCrud;
    private ArrayList<EventoPrincipal> listaEventosPrincipal;
    private ArrayList<Recurso> listaRecursosSelecionados;
    private ArrayList<Palestrante> listaPalestranteSelecionados;
    ArrayList<AreaTematica> areaTema;
    Dimension s = new Dimension(59, 20);

    /** Creates new form Consultar */
    public TelaCadastroMiniCurso() {
        initComponents();
        cbEventoPrincipal.setPreferredSize(s);
        txtNome.setPreferredSize(s);
        cbAreaCiencia.setPreferredSize(s);
        cbTema.setPreferredSize(s);

        listaRecursosSelecionados = new ArrayList<Recurso>();
        connectionCrud = new mySQLcrud();
        areaTema = connectionCrud.listaAreaTematica("");
        preencherComboBoxEventoPrincipal();
        preencherComboBoxAreaCiencia();

    }

    private void preencherComboBoxAreaCiencia() {
        ArrayList<String> jaInserido = new ArrayList<String>();
        cbAreaCiencia.addItem("Selecione a area da ciência");
        for (AreaTematica a : areaTema) {
            if (!jaInserido.contains(a.getAreaCiencia())) {
                cbAreaCiencia.addItem(a.getAreaCiencia());
                jaInserido.add(a.getAreaCiencia());
            }
        }
    }

    private void preencherComboBoxAreaTema(String areaSelecionada) {
        cbTema.setPreferredSize(s);
        cbTema.removeAllItems();
        if (!areaSelecionada.equals("Selecione a area da ciência")) {
            for (AreaTematica a : areaTema) {
                if (a.getAreaCiencia().equals(areaSelecionada)) {
                    cbTema.addItem(a.getTema());
                    cbTema.setPreferredSize(s);
                }
            }
        }
    }

    private void preencherComboBoxEventoPrincipal() {
        listaEventosPrincipal = connectionCrud.listaEventoPrincipal("");
        for (EventoPrincipal a : listaEventosPrincipal) {
            cbEventoPrincipal.addItem(a.getNomeEventoPrincipal());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        lblTitulo = new javax.swing.JLabel();
        lblParamConsulta = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblNome = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        lblNumVagas = new javax.swing.JLabel();
        txtNumVagas = new javax.swing.JTextField();
        cbAreaCiencia = new javax.swing.JComboBox();
        cbEventoPrincipal = new javax.swing.JComboBox();
        cbTema = new javax.swing.JComboBox();
        lblTema = new javax.swing.JLabel();
        lblAreaCiencia = new javax.swing.JLabel();
        lblEventoPrincipal = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listRecursos = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        listPalestrantes = new javax.swing.JList();
        btRecursos = new javax.swing.JButton();
        btPalestrantes = new javax.swing.JButton();
        btConfirmar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        lblDataInicio = new javax.swing.JLabel();
        lblDataTermino = new javax.swing.JLabel();
        lblDescricao = new javax.swing.JLabel();
        txtDescricao = new javax.swing.JTextField();
        jDateTermino = new com.toedter.calendar.JDateChooser();
        jDateInicio = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblTitulo.setText("Cadastro de");
        jPanel1.add(lblTitulo);

        lblParamConsulta.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        lblParamConsulta.setText("Mini-Cursos");
        jPanel1.add(lblParamConsulta);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        lblNome.setText("Nome:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblNome, gridBagConstraints);

        txtNome.setToolTipText("Digite o nome do Mini-Curso");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 153;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(txtNome, gridBagConstraints);

        lblNumVagas.setText("Número de Vagas:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblNumVagas, gridBagConstraints);

        txtNumVagas.setToolTipText("Digite o numero máximo de vagas disponíves para este mini curso");
        txtNumVagas.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 98;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(txtNumVagas, gridBagConstraints);

        cbAreaCiencia.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbAreaCienciaItemStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.ipadx = 103;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        jPanel2.add(cbAreaCiencia, gridBagConstraints);

        cbEventoPrincipal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Evento principal" }));
        cbEventoPrincipal.setToolTipText("Selecione o evento principal que se encontra o mini-curso");
        cbEventoPrincipal.setAutoscrolls(true);
        cbEventoPrincipal.setMaximumSize(new java.awt.Dimension(59, 32767));
        cbEventoPrincipal.setMinimumSize(new java.awt.Dimension(59, 20));
        cbEventoPrincipal.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.ipadx = 103;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(cbEventoPrincipal, gridBagConstraints);

        cbTema.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " " }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.ipadx = 103;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
        jPanel2.add(cbTema, gridBagConstraints);

        lblTema.setText("Tema:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 10, 5);
        jPanel2.add(lblTema, gridBagConstraints);

        lblAreaCiencia.setText("Área da Ciência:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 10, 5);
        jPanel2.add(lblAreaCiencia, gridBagConstraints);

        lblEventoPrincipal.setText("Evento Principal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblEventoPrincipal, gridBagConstraints);

        listRecursos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " ", " ", " ", " ", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listRecursos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(listRecursos);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.ipadx = 120;
        jPanel2.add(jScrollPane1, gridBagConstraints);

        listPalestrantes.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " ", " ", " ", " ", " ", " ", " ", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listPalestrantes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(listPalestrantes);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.ipadx = 120;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel2.add(jScrollPane2, gridBagConstraints);

        btRecursos.setText("Adicionar Recursos");
        btRecursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRecursosActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 0);
        jPanel2.add(btRecursos, gridBagConstraints);

        btPalestrantes.setText("Adicionar Palestrantes");
        btPalestrantes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPalestrantesActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 0, 6, 0);
        jPanel2.add(btPalestrantes, gridBagConstraints);

        btConfirmar.setText("Confirmar");
        btConfirmar.setToolTipText("Confirmar Cadastro de Mini-Curso");
        btConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConfirmarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(34, 81, 1, 0);
        jPanel2.add(btConfirmar, gridBagConstraints);

        btCancelar.setText("Cancelar");
        btCancelar.setToolTipText("Cancelar e retornar para a tela anterior");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(34, 45, 0, 40);
        jPanel2.add(btCancelar, gridBagConstraints);

        lblDataInicio.setText("Data de Início:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblDataInicio, gridBagConstraints);

        lblDataTermino.setText("Data de Término:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblDataTermino, gridBagConstraints);

        lblDescricao.setText("Descrição:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblDescricao, gridBagConstraints);

        txtDescricao.setToolTipText("Digite uma breve descrição do Mini-Curso");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 153;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(txtDescricao, gridBagConstraints);

        jDateTermino.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel2.add(jDateTermino, gridBagConstraints);

        jDateInicio.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 12;
        jPanel2.add(jDateInicio, gridBagConstraints);

        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jPanel2.add(jLabel1, new java.awt.GridBagConstraints());

        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("Atenção: Todos os campos são obrigatórios!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        jPanel2.add(jLabel2, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btRecursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRecursosActionPerformed
        // TODO add your handling code here:
        TelaAdicionarRecursos t = new TelaAdicionarRecursos();
        t.setFormilario(this);
        t.setVisible(true);
    }//GEN-LAST:event_btRecursosActionPerformed

    

    public void setListaRecursosSelecionados(ArrayList<Recurso> listaRecursosObj) {
        listaRecursosSelecionados = listaRecursosObj;
        DefaultListModel listaRecursosModel = new DefaultListModel();

        for (Recurso r : listaRecursosObj) {
            listaRecursosModel.addElement(r.getNomeRecurso());
        }
        listRecursos.setModel(listaRecursosModel);
    }

    public void setListaPalestranteSelecionados(ArrayList<Palestrante> listaPalestranteObj) {
        listaPalestranteSelecionados = listaPalestranteObj;
        DefaultListModel listaRecursosModel = new DefaultListModel();

        for (Palestrante p : listaPalestranteObj) {
            listaRecursosModel.addElement(p.getNomePalestrante());
        }
        listPalestrantes.setModel(listaRecursosModel);
    }

    private void btPalestrantesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPalestrantesActionPerformed

        TelaAdicionarPalestrantes t = new TelaAdicionarPalestrantes();
        t.setFormilario(this);
        t.setVisible(true);
    }//GEN-LAST:event_btPalestrantesActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        //this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_btCancelarActionPerformed

    private boolean verificaCampos(HashMap<Integer, Object> campos) {

        String nomeMiniCurso = txtNome.getText();
        String descricaoMiniCurso = txtDescricao.getText();
        String eventoPrincipal = (String) cbEventoPrincipal.getSelectedItem();
        String numVagasMiniCurso = txtNumVagas.getText();
        Date dataInicio = jDateInicio.getDate();
        Date dataTermino = jDateInicio.getDate();
        String areaTematica = (String) cbTema.getSelectedItem();
        ListModel listaRecursos = listRecursos.getModel();
        ListModel listaPalestrante = listPalestrantes.getModel();


        campos.clear();
        campos.put(Constants.NOME_MINICURSO, nomeMiniCurso);
        campos.put(Constants.DESCRICAO_MINICURSO, descricaoMiniCurso);
        campos.put(Constants.EVENTO_PRINCIPAL, eventoPrincipal);
        campos.put(Constants.NUM_VAGAS_MINICURSO, numVagasMiniCurso);
        campos.put(Constants.DATA_INICIO, dataInicio);
        campos.put(Constants.DATA_TERMINO, dataTermino);
        campos.put(Constants.AREA_TEMATICA, areaTematica);
        campos.put(Constants.LISTA_RECUSOS_MINICURSO, listaRecursosSelecionados);
        campos.put(Constants.LISTA_PALESTRANTES_MINICURSO, listaPalestranteSelecionados);



        if (!numVagasMiniCurso.equals("")) {
            campos.put(Constants.NUM_VAGAS_MINICURSO, Integer.parseInt(numVagasMiniCurso));
        }

        if (nomeMiniCurso.equals("") || nomeMiniCurso.trim().equals("")) {
            lblNome.setForeground(Color.red);
            txtNome.setText("");
            txtNome.grabFocus();
            JOptionPane.showMessageDialog(null, "Preencha o nome do mini curso corretamente");
            return false;
        } else {
            lblNome.setForeground(Color.black);
            if (descricaoMiniCurso.equals("") || descricaoMiniCurso.trim().equals("")) {
                lblDescricao.setForeground(Color.red);
                txtDescricao.setText("");
                txtDescricao.grabFocus();
                JOptionPane.showMessageDialog(null, "Preencha a descrição do mini curso corretamente");
                return false;
            } else {
                lblDescricao.setForeground(Color.black);
                if (numVagasMiniCurso.equals("") || !numVagasMiniCurso.matches("^[0-9]*$")) {
                    lblNumVagas.setForeground(Color.red);
                    txtNumVagas.setText("");
                    txtNumVagas.grabFocus();
                    JOptionPane.showMessageDialog(null, "Preencha a quantidade de vagas do mini curso corretamente");
                    return false;
                } else {
                    if (!numVagasMiniCurso.equals("") && !numVagasMiniCurso.matches("^[0-9]*$")) {
                        lblNumVagas.setForeground(Color.red);
                        txtNumVagas.setText("");
                        txtNumVagas.grabFocus();
                        JOptionPane.showMessageDialog(null, "Preencha a quantidade de vagas do mini curso corretamente (SOMENTE NÚMEROS)");
                        return false;
                    } else {
                        lblNumVagas.setForeground(Color.black);
                        if (cbEventoPrincipal.getSelectedIndex() == 0) {
                            lblEventoPrincipal.setForeground(Color.red);
                            JOptionPane.showMessageDialog(null, "Selecione um eventro principal");
                            return false;
                        } else {
                            lblEventoPrincipal.setForeground(Color.black);
                            if (dataInicio == null) {
                                lblDataInicio.setForeground(Color.red);
                                JOptionPane.showMessageDialog(null, "Selecione uma data de inicio");
                                return false;
                            } else {
                                lblDataInicio.setForeground(Color.black);
                                if (dataTermino == null) {
                                    lblDataTermino.setForeground(Color.red);
                                    JOptionPane.showMessageDialog(null, "Selecione uma data de temino");
                                    return false;
                                } else {
                                    lblDataTermino.setForeground(Color.black);
                                    if (cbAreaCiencia.getSelectedIndex() == 0) {
                                        lblAreaCiencia.setForeground(Color.red);
                                        JOptionPane.showMessageDialog(null, "Selecione uma área da ciência");
                                        return false;
                                    } else {
                                        lblAreaCiencia.setForeground(Color.black);
                                        if (cbTema.getSelectedItem() == null) {
                                            lblTema.setForeground(Color.red);
                                            JOptionPane.showMessageDialog(null, "Selecione um tema");
                                            return false;
                                        } else {
                                            lblTema.setForeground(Color.black);
                                            if (listaPalestrante.getElementAt(0) == (String) " ") {
                                                btPalestrantes.setForeground(Color.red);
                                                JOptionPane.showMessageDialog(null, "Selecione um palestrante");
                                                return false;
                                            } else {
                                                btPalestrantes.setForeground(Color.black);
                                                return true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private void btConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfirmarActionPerformed


        HashMap<Integer, Object> listaCampos = new HashMap<Integer, Object>();

        if (verificaCampos(listaCampos)) {
            int codAg = 0;
            int codAreaTematica = 0;
            String nomeMinicurso = (String) listaCampos.get(Constants.NOME_MINICURSO);
            String descricaoMinicurso = (String) listaCampos.get(Constants.DESCRICAO_MINICURSO);
            int numVagas = (Integer) listaCampos.get(Constants.NUM_VAGAS_MINICURSO);
            ArrayList<Recurso> listaRecursos = (ArrayList<Recurso>) listaCampos.get(Constants.LISTA_RECUSOS_MINICURSO);
            ArrayList<Palestrante> listaPalestrante = (ArrayList<Palestrante>) listaCampos.get(Constants.LISTA_PALESTRANTES_MINICURSO);
            String vraivelEventoPrincipal = (String) listaCampos.get(Constants.EVENTO_PRINCIPAL);
            String areaTematica = (String) listaCampos.get(Constants.AREA_TEMATICA);
            EventoPrincipal evento = null;
            AreaTematica area;

            for (EventoPrincipal e : listaEventosPrincipal) {
                if (e.getNomeEventoPrincipal().equals(vraivelEventoPrincipal)) {
                    evento = e;
                    codAg = evento.getCodAgenda();
                }
            }


            for (AreaTematica a : areaTema) {
                if (a.getTema().equals(areaTematica)) {
                    area = a;
                    codAreaTematica = area.getCodAreaTematica();
                }
            }

            connectionCrud.inserirMinicurso(codAg, codAreaTematica, nomeMinicurso, numVagas, descricaoMinicurso, evento, listaRecursos, listaPalestrante);
            JOptionPane.showMessageDialog(null, "Cadastro do minicurso realizado com sucesso");
            this.dispose();
        }
    }//GEN-LAST:event_btConfirmarActionPerformed

    private void cbAreaCienciaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbAreaCienciaItemStateChanged

        String itemSelecionado = (String) cbAreaCiencia.getSelectedItem();
        if (!itemSelecionado.equals("Selecione a area da ciência")) {
            preencherComboBoxAreaTema(itemSelecionado);
        }
    }//GEN-LAST:event_cbAreaCienciaItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaConsulta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btConfirmar;
    private javax.swing.JButton btPalestrantes;
    private javax.swing.JButton btRecursos;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbAreaCiencia;
    private javax.swing.JComboBox cbEventoPrincipal;
    private javax.swing.JComboBox cbTema;
    private com.toedter.calendar.JDateChooser jDateInicio;
    private com.toedter.calendar.JDateChooser jDateTermino;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblAreaCiencia;
    private javax.swing.JLabel lblDataInicio;
    private javax.swing.JLabel lblDataTermino;
    private javax.swing.JLabel lblDescricao;
    private javax.swing.JLabel lblEventoPrincipal;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblNumVagas;
    private javax.swing.JLabel lblParamConsulta;
    private javax.swing.JLabel lblTema;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JList listPalestrantes;
    private javax.swing.JList listRecursos;
    private javax.swing.JTextField txtDescricao;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtNumVagas;
    // End of variables declaration//GEN-END:variables
}
